package order

import (
	"github.com/labstack/echo"

	"shop_be/util"
	"shop_be/model"
	"strconv"
)

func OrderRouter(app *echo.Echo) {

	app.POST("/order/create", func(c echo.Context) error {
		uid := c.FormValue("uid")
		id := c.FormValue("product")
		address := c.FormValue("address")

		msg := createOrder(uid, id,address)
		return c.JSON(200, msg)
	})

	app.GET("/order/find/:uid", func(c echo.Context) error {

		uid := c.Param("uid")
		msg := findOrder(uid)
		return c.JSON(200, msg)
	})

	app.POST("/shopcart/create", func(c echo.Context) error {
		shopcart := c.FormValue("shopcart")
		uid := c.FormValue("uid")
		msg := createShopcart(shopcart, uid)
		return c.JSON(200, msg)

	})

	app.GET("/shopcart/find/:uid", func(c echo.Context) error {
		uid := c.Param("uid")
		msg := findShopcart(uid)
		return c.JSON(200, msg)
	})
	app.GET("/order/all/get", func(c echo.Context) error {

		msg := getAllOrder()
		return c.JSON(200, msg)
	})

	app.POST("/order/delete", func(c echo.Context) error {
		id := c.FormValue("id")
		id2, _ := strconv.Atoi(id)
		o := model.Order{}
		o.Id = id2
		util.Db.Delete(o)
		return c.JSON(200, "")
	})
}
